<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script>
    <script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
</head>

<body>
    <div id="app" class="demo">
        <hr>
        <div>{{msg}}</div>
        <hr>
        <img style="width: 200px;height: 200px; background-color: rebeccapurple;" :src="img_path" >
        <button @click="getGoods">获取商品</button>
    </div>
</body>
<script>

    //免费api网址：https://api.uomg.com/  https://api.oioweb.cn

    let api = "https://api.uomg.com/api/rand.avatar?sort=男&format=json";

    const HelloVueApp = {
        data() {
            return {
                msg: 'hello world',
                img_path:'https://www.baidu.com/img/PCfb_5bf082d29588c07f842ccde3f97243ea.png'
            }
        },
        methods: {
            getGoods() {
                axios
                    .post(api)
                    .then(response =>{
                        this.msg = response,
                        this.img_path = response.data.imgurl
                    })
                    .catch(function (error) { // 请求失败处理
                        console.log(error);
                    });
            }
        }
    }

    Vue.createApp(HelloVueApp).mount('#app')
</script>

</html>